Skip to content

Add admin action to import KJV Bible data#39

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/add-admin-import-button-kjv
Draft

Add admin action to import KJV Bible data#39
Copilot wants to merge 3 commits intomasterfrom
copilot/add-admin-import-button-kjv

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 8, 2026

Adds a Django admin action to trigger the existing import_kjv management command from the admin UI. Previously only accessible via CLI.

Changes

  • run_kjv_import() helper: Wraps call_command('import_kjv', '--clear') with logging and exception handling
  • import_kjv_bible admin action: Spawns daemon thread to execute import without blocking HTTP request
  • User feedback: Django messages inform admin of import status; detailed progress in server logs

Implementation

@admin.register(BibleBook)
class BibleBookAdmin(admin.ModelAdmin):
    actions = ["import_kjv_bible"]
    
    def import_kjv_bible(self, request, queryset):
        import_thread = threading.Thread(target=run_kjv_import, daemon=True)
        import_thread.start()
        messages.success(request, "KJV Bible import has been started in the background...")

Usage

Navigate to Bible Books admin → select any book → choose "Import KJV Bible" from actions dropdown → click Go.

Screenshots

Admin action dropdown:
Admin action dropdown

Success message:
Success message

Notes

  • Daemon thread allows clean shutdown but may lose in-flight imports
  • Standard admin action permissions apply (staff users with change permission)
  • No new dependencies required
Original prompt

Add an admin-only import button/action for importing the KJV Bible in the Django admin.

Currently the repository provides a management command (python manage.py import_kjv) and helper scripts to import the KJV Bible, but there is no admin UI to trigger the import. The user asked for a button visible only to admins to run the import script.

Make the following changes:

  1. Update python_anywhere_website/bible/admin.py to add an admin action (and a short helper) on the BibleBook admin that allows staff users with change permission to trigger the import from the admin UI. The action should:

    • Be named "Import KJV Bible" and appear in the actions dropdown on the BibleBook changelist.
    • Run the existing management command by calling Django's call_command('import_kjv', '--clear') so the import runs and replaces existing data.
    • Run the import in a background thread so the admin request does not block or time out.
    • Use Django messages (messages.success / messages.error) to inform the user that the import was started or if it failed immediately.
    • Be careful to limit access to staff users (use the standard admin action permission behavior).
  2. Add a small helper function in admin.py to run call_command in a try/except and log exceptions.

  3. Add unit test scaffolding (optional) is not required for this PR; focus on functional admin action.

Please modify only the file python_anywhere_website/bible/admin.py. Keep the rest of the repo unchanged.

Rationale: This is a minimal safe change that adds an admin-only control to run the already-existing import logic without adding new dependencies or a background task system. It avoids blocking requests by running in a background thread and uses standard admin permissions to restrict access.

Files to change:

  • python_anywhere_website/bible/admin.py

Make sure the PR includes a concise title and description explaining the change and how to use the new admin action.

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 8, 2026 01:14
- Added helper function run_kjv_import() to execute import in background
- Added import_kjv_bible admin action to BibleBookAdmin
- Action runs import_kjv management command with --clear flag
- Runs in background thread to prevent request timeouts
- Uses Django messages to inform users of import status
- Applied Black formatting to maintain code style

Co-authored-by: bamaham93 <57500397+bamaham93@users.noreply.github.com>
- Added daemon=True to Thread constructor
- Ensures background thread doesn't prevent application shutdown
- Addresses code review feedback

Co-authored-by: bamaham93 <57500397+bamaham93@users.noreply.github.com>
Copilot AI changed the title [WIP] Add admin-only import action for KJV Bible Add admin action to import KJV Bible data Jan 8, 2026
Copilot AI requested a review from bamaham93 January 8, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants